@extends('admin.common.base-master')

@section('html-head')

@endsection

@section('html-body')
    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <a href="{{route('Admin.Home.sectionList')}}">栏目列表</a>
        </div>

        @include('admin.common.home-header')

        <div class="filter-box clearfix">

            <div class="fr">
                <a class="addBtn" href="{{route("Admin.Home.sectionSet")}}">新增</a>
            </div>
        </div>
        <div class="table-box">
            <table class="table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>标题</th>
                    <th>图标</th>
                    <th>排序</th>
                    <th>首页推荐</th>
                    <th>推荐图</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @if(count($classify) > 0)
                    @foreach($classify as $banner)
                        <tr id="banner_{{$banner->id}}">
                            <td>{{$banner->id}}</td>
                            <td>{{$banner->name}}</td>
                            <td class="account-td" style="width: 5%;">
                                <span class="photo" style="border-radius: 100%;display:initial">
                                    @if($banner->img_id !== 0)
                                        <a target="_blank" href="{{\App\Http\Services\FileManager::getImgUrl($banner->img_id)}}"  class="openimg" data-key="{{$banner->img_id}}"><img src="{{\App\Http\Services\FileManager::getImgUrl($banner->img_id)}}" alt=""></a>
                                    @else
                                        <img src="{{url('images/default-avatar.png')}}" alt="">
                                    @endif
                                </span>
                            </td>
{{--                            <td>{{$banner->link_url}}</td>--}}
                            <td>{{$banner->sort}}</td>
                            <td>@if($banner->home_show == 0)<span class="color2">不推荐</span>@else<span class="color4">推荐</span> @endif</td>
                            <td class="account-td" style="width: 5%;">
                                <span class="photo" style="display:initial">
                                    @if($banner->advert_img_id != 0)
                                        <a target="_blank" href="{{\App\Http\Services\FileManager::getImgUrl($banner->advert_img_id)}}"  class="openimg" data-key="{{$banner->advert_img_id}}"><img src="{{\App\Http\Services\FileManager::getImgUrl($banner->advert_img_id)}}" alt=""></a>
                                    @else
                                        <img src="{{url('images/default-avatar.png')}}" alt="">
                                    @endif
                                </span>
                            </td>
                            <td><a class="color2" href="{{route("Admin.Home.sectionSet")}}?id={{$banner->id}}">编辑</a> <span>|</span> <a href="javascript:void(0);" class="del" data-id="{{$banner->id}}">删除 </a></td>
                        </tr>
                    @endforeach
                @endif
                </tbody>
            </table>
        </div>
    </div>
    <script>
        $(function(){

            $(document).on("click",".del",function(){
                var id = $(this).attr("data-id");
                noty({
                    text: '你确定要删除吗?',
                    buttons: [
                        {addClass: 'btn btn-primary', text: '确定', onClick: function($noty) {
                                $noty.close();
                                $.ajax({
                                    url:'{{route("Api.Admin.sys.delClassify")}}',
                                    type:'post',
                                    dataType:'json',
                                    data:{id:id},
                                    success:function(obj){
                                        if(obj.level == "success"){
                                            $("#banner_"+id).hide('slow');
                                        }else{
                                            noty({type:obj.level,text:obj.message,timeout:600});
                                        }
                                    },
                                    error:function(obj){
                                        console.log(obj);
                                    }

                                });
                            }
                        },
                        {addClass: 'btn btn-danger', text: '取消', onClick: function($noty) {
                                $noty.close();
                            }
                        }
                    ]
                });

            });
        });
    </script>
@endsection